using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Srvtools;

namespace cBCust
{
    public partial class Form1 : InfoForm
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void infoDataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {

        }

       // //
        public string GetToday()
        {
            return string.Format("{0:yyyyMMdd}", DateTime.Today);
        }

        public string GetNowTime()
        {

            return string.Format("{0:hhmmss}", DateTime.Now);
        }

        public string GetUser()
        {
            return CliUtils.fLoginUser;
        }
        // //
        public string GetCUST()
        {
            return InfoTextBox01.Text;
        }

        private void Label02_Click(object sender, EventArgs e)
        {
            
        }

        private void Label13_Click(object sender, EventArgs e)
        {

        }

        private void Label21_Click(object sender, EventArgs e)
        {

        }

        private void InfoComboBox2_SelectedIndexChanged(object sender, EventArgs e)
        {

        }

        private void ibsMaster_BeforeEdit(object sender, EventArgs e)
        {
            InfoTextBox3.Text = CliUtils.fLoginUser.ToString();

            //在新增就顯示建檔時間 
            infoTextBox11.Text = DateTime.Now.ToLongTimeString();       
        }

        private void ibsMaster_CurrentChanged(object sender, EventArgs e)
        {
          string state = inMaster.GetCurrentState();
          if (state == "Inserting" || state == "Editing" || state == "Initial" || state == "Browsed")
          {
              //修改時間顯示
              string UPDATE_TIME = ((DataRowView)ibsMaster.Current)["UPDATE_TIME"].ToString();
              if (UPDATE_TIME.Length == 6)
              { infoTextBox11.Text = Convert.ToDateTime(UPDATE_TIME.Substring(0, 2) + ":" + UPDATE_TIME.Substring(2, 2) + ":" + UPDATE_TIME.Substring(4, 2)).ToLongTimeString(); }
              else if (UPDATE_TIME.Length == 0)
                  infoTextBox11.Text = "";

              //建檔時間顯示
              string CREATE_TIME = ((DataRowView)ibsMaster.Current)["CREATE_TIME"].ToString();
              if (CREATE_TIME.Length == 6)
              { infoTextBox5.Text = Convert.ToDateTime(CREATE_TIME.Substring(0, 2) + ":" + CREATE_TIME.Substring(2, 2) + ":" + CREATE_TIME.Substring(4, 2)).ToLongTimeString(); }
              else if (CREATE_TIME.Length == 0)
                  infoTextBox5.Text = "";
          }
            
        }

        private void ibsMaster_AddingNew(object sender, AddingNewEventArgs e)
        {
            ((DataRowView)ibsMaster.Current).EndEdit();
            //在新增就顯示建檔時間日期
            infoTextBox5.Text = DateTime.Now.ToLongTimeString();
        }

        private void bindingNavigatorEditItem1_Click(object sender, EventArgs e)
        {
            //以string儲存,在按下修改時  
            ((DataRowView)ibsMaster.Current)["UPDATE_USER"] = CliUtils.fLoginUser;
            ((DataRowView)ibsMaster.Current)["UPDATE_DATE"] = string.Format("{0:yyyyMMdd}", DateTime.Now.Date);
            ((DataRowView)ibsMaster.Current)["UPDATE_TIME"] = string.Format("{0:hhmmss}", DateTime.Now);

        }

        private void ibsMaster_AfterEdit(object sender, EventArgs e)
        {
            //以string儲存
            ((DataRowView)ibsMaster.Current)["UPDATE_USER"] = CliUtils.fLoginUser;
            ((DataRowView)ibsMaster.Current)["UPDATE_DATE"] = string.Format("{0:yyyyMMdd}", DateTime.Now.Date);
            ((DataRowView)ibsMaster.Current)["UPDATE_TIME"] = string.Format("{0:hhmmss}", DateTime.Now);
        }

        private void ibsDetail1_BeforeEdit(object sender, EventArgs e)
        {
            //記錄Detail的修改時間日期
            ((DataRowView)ibsDetail1.Current)["UPDATE_USER"] = CliUtils.fLoginUser;
            ((DataRowView)ibsDetail1.Current)["UPDATE_DATE"] = string.Format("{0:yyyyMMdd}", DateTime.Now.Date);
            ((DataRowView)ibsDetail1.Current)["UPDATE_TIME"] = string.Format("{0:hhmmss}", DateTime.Now);
        }

        private void ibsDetail2_BeforeEdit(object sender, EventArgs e)
        {
            //記錄Detail的修改時間日期
            ((DataRowView)ibsDetail2.Current)["UPDATE_USER"] = CliUtils.fLoginUser;
            ((DataRowView)ibsDetail2.Current)["UPDATE_DATE"] = string.Format("{0:yyyyMMdd}", DateTime.Now.Date);
            ((DataRowView)ibsDetail2.Current)["UPDATE_TIME"] = string.Format("{0:hhmmss}", DateTime.Now);
        }

        private void infoDataGridView2_Click(object sender, EventArgs e)
        {
            //重新設定明細欄位的ReadOnly屬性(因為使用AutoDisableControl會造成回歸預設值False)
            this.NO_CONTACT.ReadOnly = true;
        }

        private void infoDataGridView3_Click(object sender, EventArgs e)
        {
            //重新設定明細欄位的ReadOnly屬性(因為使用AutoDisableControl會造成回歸預設值False)
            this.infoDataGridView3.ReadOnly = true;
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            this.Column1.Visible = false;
        }

        //public bool CheckCONTACT(string Value)
        //{
        //    if (((DataRowView)ibsDetail2.Current)["NM_ATT"].ToString().Length == 0)
        //        return false;
        //    else
        //        return true;
        //}

        //public bool CheckTEL(string Value)
        //{
        //    if (((DataRowView)ibsDetail2.Current)["NO_TEL"].ToString().Length == 0)
        //        return false;
        //    else
        //        return true;
        //}

        //public bool CheckADDR(string Value)
        //{
        //    if (((DataRowView)ibsDetail1.Current).ToString().Length == 0)
        //        return false;
        //    else
        //        return true;
        //}

        private void bindingNavigatorPrintItem_Click(object sender, EventArgs e)
        {
            rBCust1.Form1 Print = new rBCust1.Form1();
            Print.Wstr="B_CUST.ID_CUST='"+InfoTextBox01.Text+"'";
            Print.MdiParent = this.MdiParent;
            Print.WindowState = FormWindowState.Maximized;
            Print.Show();

        }

        private void inMaster_StateChanged(object sender, InfoNavigatorStateChangedEventArgs e)
        {
            //將DateTimePicker設為不可改
            this.InfoDateTimePicker0.Enabled = false;
            this.InfoDateTimePicker1.Enabled = false;
        }

        private void bindingNavigatorAddNewItem1_MouseUp(object sender, MouseEventArgs e)
        {
            //將DateTimePicker設為不可改
            this.InfoDateTimePicker0.Enabled = false;
            this.InfoDateTimePicker1.Enabled = false;
        }

        
        
    }
}

